/*
 * author: Andriamananony, Meß, Falk
 */

package auftrag;

import java.util.ArrayList;
import java.util.Collections;

public class Variante {
	private ArrayList<Operation> arrOperation = new ArrayList<Operation>();
	private Produkt prodParent;
	private String strName;
	
	public Variante(Produkt p, int i){
		prodParent = p;
		p.addVarianteToProdukt(this);
		strName = "V"+i;
	}
	
	public void addOperation(Operation opOperation) {
		this.arrOperation.add(opOperation);
		Collections.sort(this.arrOperation);
		
		if(opOperation.getStep() > 1){
			for(Operation o : arrOperation){
				if(o.getStep() == opOperation.getStep()-1){
					opOperation.setPreviousOperation(o);
				}
			}
		}
	}

	public int numOperations() {
		return this.arrOperation.size();
	}

	public Operation getOperation(int intIndex) {
		for(Operation o : arrOperation)
			if(o.getStep() == intIndex)
				return o;
		return null;
	}
	
	public ArrayList<Operation> getOperations(){
		return this.arrOperation;
	}
	
	public int getOperationSize() {
		return this.arrOperation.size();
	}
	
	public Produkt getParent(){
		return prodParent;
	}
	
	@Override
	public String toString(){
		return strName;
	}
}
